/*******************************************************************************
 * Copyright(c) 2023 Levetop Semiconductor Co.,Led. All rights reserved.
 * @file     tftlcd_ebi_16bit.c
 * @author   UartTFT Application Team
 * @version  V0.0.1
 * @date     2023-01-12
 * @brief    This file contains the interface initialization and basic
 *           control functions of the TFT.
 ********************************************************************************/

#include "tftlcd_init_code.h"
#include "module_select.h"
#include "tftlcd_spi.h"
#include "tftlcd_ebi_8bit.h"
#include "tftlcd_ebi_16bit.h"
#include "tftlcd_qspi.h"

void lt_tft_init_code_1(void)
{
	TFT_CommandWrite(0x11);
	DelayMS(120);                //ms

	// reference: 0=0x00 1=0x60  2=0xC0 3=0xA0
	// reference : 0=0x48 1=0x08  2=0x08 3=0xE8
	// ILI9488: reference : 0=0x48 1=0x28  2=0x88 3=0xf8
	TFT_CommandWrite(0x36);
#if (LT_TFT_DIR == 0)
	TFT_DataWrite(0x48);
#elif (LT_TFT_DIR == 1)
	TFT_DataWrite(0x28);
#elif (LT_TFT_DIR == 2)
	TFT_DataWrite(0x88);
#elif (LT_TFT_DIR == 3)
	TFT_DataWrite(0xf8);
#endif

	TFT_CommandWrite(0x3A);
	TFT_DataWrite(0x55);

	TFT_CommandWrite(0xB2);
	TFT_DataWrite(0x0C);
	TFT_DataWrite(0x0C);
	TFT_DataWrite(0x00);
	TFT_DataWrite(0x33);
	TFT_DataWrite(0x33);

	TFT_CommandWrite(0xB7);
	TFT_DataWrite(0x46);   //VGH=13.65V,VGL=-11.38V

	TFT_CommandWrite(0xBB);
	TFT_DataWrite(0x1B);

	TFT_CommandWrite(0xC0);
	TFT_DataWrite(0x2C);

	TFT_CommandWrite(0xC2);
	TFT_DataWrite(0x01);

	TFT_CommandWrite(0xC3);
	TFT_DataWrite(0x0F);

	TFT_CommandWrite(0xC4);
	TFT_DataWrite(0x20);

	TFT_CommandWrite(0xC6);
	TFT_DataWrite(0x0F);

	TFT_CommandWrite(0xD0);
	TFT_DataWrite(0xA4);
	TFT_DataWrite(0xA1);

	TFT_CommandWrite(0xD6);
	TFT_DataWrite(0xA1);

	TFT_CommandWrite(0xE0);
	TFT_DataWrite(0xF0);
	TFT_DataWrite(0x00);
	TFT_DataWrite(0x06);
	TFT_DataWrite(0x04);
	TFT_DataWrite(0x05);
	TFT_DataWrite(0x05);
	TFT_DataWrite(0x31);
	TFT_DataWrite(0x44);
	TFT_DataWrite(0x48);
	TFT_DataWrite(0x36);
	TFT_DataWrite(0x12);
	TFT_DataWrite(0x12);
	TFT_DataWrite(0x2B);
	TFT_DataWrite(0x34);

	TFT_CommandWrite(0xE1);
	TFT_DataWrite(0xF0);
	TFT_DataWrite(0x0B);
	TFT_DataWrite(0x0F);
	TFT_DataWrite(0x0F);
	TFT_DataWrite(0x0D);
	TFT_DataWrite(0x26);
	TFT_DataWrite(0x31);
	TFT_DataWrite(0x43);
	TFT_DataWrite(0x47);
	TFT_DataWrite(0x38);
	TFT_DataWrite(0x14);
	TFT_DataWrite(0x14);
	TFT_DataWrite(0x2C);
	TFT_DataWrite(0x32);
//	TFT_CommandWrite(0x21);

	TFT_CommandWrite(0x29);
}

void lt_tft_init_code_2(void)
{
	TFT_CommandWrite(0x11);
	DelayMS(120); // Delay 120ms

	// reference: 0=0x00 1=0x60  2=0xC0 3=0xA0
	TFT_CommandWrite(0x36);
#if (LT_TFT_DIR == 0)
	TFT_DataWrite(0x00);
#elif (LT_TFT_DIR == 1)
	TFT_DataWrite(0x60);
#elif (LT_TFT_DIR == 2)
	TFT_DataWrite(0xc0);
#elif (LT_TFT_DIR == 3)
	TFT_DataWrite(0xA0);
#endif

	TFT_CommandWrite(0x3a);
	TFT_DataWrite(0x05);

	TFT_CommandWrite(0xb2);
	TFT_DataWrite(0x0c);
	TFT_DataWrite(0x0c);
	TFT_DataWrite(0x00);
	TFT_DataWrite(0x33);
	TFT_DataWrite(0x33);

	TFT_CommandWrite(0xb7);
	TFT_DataWrite(0x35);

	TFT_CommandWrite(0xbb);
	TFT_DataWrite(0x19);

	TFT_CommandWrite(0xc0);
	TFT_DataWrite(0x2c);

	TFT_CommandWrite(0xc2);
	TFT_DataWrite(0x01);

	TFT_CommandWrite(0xc3);
	TFT_DataWrite(0x0d); // GVDD=4.2V

	TFT_CommandWrite(0xc4);
	TFT_DataWrite(0x20);

	TFT_CommandWrite(0xc6);
	TFT_DataWrite(0x0f); // Frame=60Hz

	TFT_CommandWrite(0xd0);
	TFT_DataWrite(0xa4);
	TFT_DataWrite(0xa1);

	TFT_CommandWrite(0xe0);
	TFT_DataWrite(0xd0);
	TFT_DataWrite(0x00);
	TFT_DataWrite(0x05);
	TFT_DataWrite(0x0f);
	TFT_DataWrite(0x10);
	TFT_DataWrite(0x28);
	TFT_DataWrite(0x34);
	TFT_DataWrite(0x50);
	TFT_DataWrite(0x44);
	TFT_DataWrite(0x3a);
	TFT_DataWrite(0x0b);
	TFT_DataWrite(0x06);
	TFT_DataWrite(0x11);
	TFT_DataWrite(0x20);

	TFT_CommandWrite(0xe1);
	TFT_DataWrite(0xd0);
	TFT_DataWrite(0x00);
	TFT_DataWrite(0x05);
	TFT_DataWrite(0x0a);
	TFT_DataWrite(0x0b);
	TFT_DataWrite(0x16);
	TFT_DataWrite(0x32);
	TFT_DataWrite(0x40);
	TFT_DataWrite(0x4a);
	TFT_DataWrite(0x2b);
	TFT_DataWrite(0x1b);
	TFT_DataWrite(0x1c);
	TFT_DataWrite(0x22);
	TFT_DataWrite(0x1f);

	TFT_CommandWrite(0x29);

//	TFT_CommandWrite(0x21);
}
